var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, o, i) {
    var n, a = arguments.length, r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i); else for (var s = t.length - 1; 0 <= s; s--) (n = t[s]) && (r = (a < 3 ? n(r) : 3 < a ? n(e, o, r) : n(e, o)) || r);
    return 3 < a && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameConfig"), s = e("GameData"), c = e("AdManager"), l = e("UIManager"), d = e("WebManager"), u = e("Global"), p = cc._decorator, h = p.ccclass, f = p.property, g = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.target = null, t.btnNode = null, t.touchArea = null, t.shadow = null, t.touchId = null, 
        t.isCheck = !1, t.isLoad = !1, t.pos = cc.v2(), t.type = "diamond", t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        r.GC.isVaild("eggsGift_" + this.type) || s.GD.giftCountMap[this.type] ? this.node.destroy() : (cc.systemEvent.on("draw_loaded", this.doLoad, this), 
        this.node.active = !1);
    }, t.prototype.onEnable = function() {
        this.isLoad && (r.GC.drawTodayDrawNum == r.GC.drawUpperLimit ? this.addTouchEvent() : (cc.systemEvent.on("draw_finished", this.doOpen, this), 
        this.node.active = !1));
    }, t.prototype.onDisable = function() {
        this.removeTouchEvent();
    }, t.prototype.doLoad = function() {
        this.isLoad || (this.isLoad = !0, cc.systemEvent.off("draw_loaded", this.doLoad, this), 
        r.GC.drawTodayDrawNum == r.GC.drawUpperLimit ? (this.node.active = !0, this.addTouchEvent()) : (cc.systemEvent.on("draw_finished", this.doOpen, this), 
        this.node.active = !1));
    }, t.prototype.doOpen = function() {
        r.GC.drawTodayDrawNum == r.GC.drawUpperLimit && (this.node.active = !0, this.addTouchEvent(), 
        cc.systemEvent.off("draw_finished", this.doOpen, this));
    }, t.prototype.onClick = function() {
        var t = this;
        if (GA.Info.underCheck && r.GC.isDebug) return "diamond" == this.type ? (s.GD.updateNumber(this.type, r.GC.giftDiamond), 
        l.default.getInstance().loadPopPnl("reward", {
            type: u.RewardType.DIAMOND,
            num: r.GC.giftDiamond
        })) : (s.GD.updateNumber(this.type, r.GC.giftPiece), l.default.getInstance().loadPopPnl("reward", {
            type: u.RewardType.PIECE,
            num: r.GC.giftPiece
        })), this.target.setPosition(this.pos), s.GD.giftCountMap[this.type] = 1, void this.node.destroy();
        d.default.getInstance().sentLog("点击抽奖界面" + this.type + "彩蛋视频按键"), c.default.getInstance().showVideoAd("draw_" + this.type, function() {
            "diamond" == t.type ? (s.GD.updateNumber(t.type, r.GC.giftDiamond), l.default.getInstance().loadPopPnl("reward", {
                type: u.RewardType.DIAMOND,
                num: r.GC.giftDiamond
            })) : (s.GD.updateNumber(t.type, r.GC.giftPiece), l.default.getInstance().loadPopPnl("reward", {
                type: u.RewardType.PIECE,
                num: r.GC.giftPiece
            })), t.target.setPosition(t.pos), s.GD.giftCountMap[t.type] = 1, t.node.destroy();
        });
    }, t.prototype.start = function() {
        this.pos = this.target.getPosition();
    }, t.prototype.addTouchEvent = function() {
        this.touchArea.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.removeTouchEvent = function() {
        this.touchArea.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.touchStartHandler = function(t) {
        null == this.touchId && (this.touchId = t.getID()), this.touchId == t.getID() && (t = t.getLocation(), 
        t = this.target.convertToNodeSpaceAR(t), Math.abs(t.x) <= this.target.width / 2 && Math.abs(t.y) <= this.target.height / 2 && (this.isCheck = !0));
    }, t.prototype.touchMoveHandler = function(t) {
        cc.log(t.getID()), this.touchId == t.getID() && this.isCheck && this.target.setPosition(this.target.parent.convertToNodeSpaceAR(t.getLocation()));
    }, t.prototype.touchEndHandler = function(t) {
        var e;
        this.touchId = null, this.isCheck ? this.isCheck = !1 : (e = t.getLocation(), e = this.btnNode.convertToNodeSpaceAR(e), 
        Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (cc.tween(this.btnNode).to(.1, {
            scale: 1.1
        }).to(.1, {
            scale: 1
        }).start(), this.onClick(t)));
    }, a([ f(cc.Node) ], t.prototype, "target", void 0), a([ f(cc.Node) ], t.prototype, "btnNode", void 0), 
    a([ f(cc.Node) ], t.prototype, "touchArea", void 0), a([ f(cc.Node) ], t.prototype, "shadow", void 0), 
    a([ f ], t.prototype, "type", void 0), a([ h ], t);
}(cc.Component);

n.default = g;